<template>
  <d2-container>
    <div>
      <el-button @click="dislaoging = true" type="primary">添加</el-button>
      <el-table
        :data="tableData"
        :row-class-name="tableRowClassName" header-align="center"
        border
        style="width: 100%">
        <el-table-column
          prop="id"
          label="序号">
        </el-table-column>
        <el-table-column
          prop="user"
          label="用户名">
        </el-table-column>
        <el-table-column
          label="制定抖音价格">
          <template slot-scope="scope">
            <el-button type="warning" @click="look_price(scope.row)">制定抖音价格</el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="制定淘宝价格">
          <template slot-scope="scope">
            <el-button type="warning" @click="look_price_taobao(scope.row)">制定淘宝价格</el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="制定拼多多价格">
          <template slot-scope="scope">
            <el-button type="warning" @click="look_price_pdd(scope.row)">制定拼多多价格</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="创建时间">
          <template slot-scope="scope">
            {{scope.row.update_time}}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @current-change="handleCurrentChange"
        layout="prev, pager, next"
        :total="total">
      </el-pagination>
      <!--    制定抖音价格-->
      <el-dialog
        title="制定抖音价格"
        width="50%"
        :visible.sync="dialog">
        <el-form :model="list" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <div style="display:flex;">
            <div>
              <el-form-item label="0 - 20">
                <el-input v-model.number="list[0]" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="20.1 - 50">
                <el-input v-model.number="list[1]" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="50.1 - 100">
                <el-input v-model.number="list[2]"></el-input>
              </el-form-item>
              <el-form-item label="100.1 - 150">
                <el-input v-model.number="list[3]"></el-input>
              </el-form-item>
              <el-form-item label="150.1 - 200">
                <el-input v-model.number="list[4]"></el-input>
              </el-form-item>
              <el-form-item label="200.1 - 250">
                <el-input v-model.number="list[5]"></el-input>
              </el-form-item>
              <el-form-item label="250.1 - 300">
                <el-input v-model.number="list[6]"></el-input>
              </el-form-item>
              <el-form-item label="300.1 - 350">
                <el-input v-model.number="list[7]"></el-input>
              </el-form-item>
              <el-form-item label="350.1 - 400">
                <el-input v-model.number="list[8]"></el-input>
              </el-form-item>
              <el-form-item label="400.1-450">
                <el-input v-model.number="list[9]"></el-input>
              </el-form-item>
              <el-form-item label="450.1-500">
                <el-input v-model.number="list[10]"></el-input>
              </el-form-item>
            </div>
            <div>
              <el-form-item label="500.1-550">
                <el-input v-model.number="list[11]"></el-input>
              </el-form-item>
              <el-form-item label="550.1-600">
                <el-input v-model.number="list[12]"></el-input>
              </el-form-item>
              <el-form-item label="600.1-650">
                <el-input v-model.number="list[13]"></el-input>
              </el-form-item>
              <el-form-item label="700.1-750">
                <el-input v-model.number="list[14]"></el-input>
              </el-form-item>
              <el-form-item label="750.1-800">
                <el-input v-model.number="list[15]"></el-input>
              </el-form-item>
              <el-form-item label="800.1-850">
                <el-input v-model.number="list[16]"></el-input>
              </el-form-item>
              <el-form-item label="850.1-900">
                <el-input v-model.number="list[17]"></el-input>
              </el-form-item>
              <el-form-item label="900.1-950">
                <el-input v-model.number="list[18]"></el-input>
              </el-form-item>
              <el-form-item label="950.1-1000">
                <el-input v-model.number="list[19]"></el-input>
              </el-form-item>
              <el-form-item label="1000以上">
                <el-input v-model.number="list[20]"></el-input>
              </el-form-item>
            </div>
          </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialog = false">取消</el-button>
        <el-button type="primary" @click="make_price()">确 定</el-button>
      </span>
      </el-dialog>
<!--      制定淘宝价格-->
      <el-dialog
        title="制定淘宝价格"
        width="50%"
        :visible.sync="dialog_taobao">
        <el-form :model="list_taobao" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <div style="display:flex;">
            <div>
              <el-form-item label="0 - 20">
                <el-input v-model="list_taobao[0]" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="20.1 - 50">
                <el-input v-model="list_taobao[1]" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="50.1 - 100">
                <el-input v-model="list_taobao[2]"></el-input>
              </el-form-item>
              <el-form-item label="100.1 - 150">
                <el-input v-model="list_taobao[3]"></el-input>
              </el-form-item>
              <el-form-item label="150.1 - 200">
                <el-input v-model="list_taobao[4]"></el-input>
              </el-form-item>
              <el-form-item label="200.1 - 250">
                <el-input v-model="list_taobao[5]"></el-input>
              </el-form-item>
              <el-form-item label="250.1 - 300">
                <el-input v-model="list_taobao[6]"></el-input>
              </el-form-item>
              <el-form-item label="300.1 - 350">
                <el-input v-model="list_taobao[7]"></el-input>
              </el-form-item>
              <el-form-item label="350.1 - 400">
                <el-input v-model="list_taobao[8]"></el-input>
              </el-form-item>
              <el-form-item label="400.1-450">
                <el-input v-model="list_taobao[9]"></el-input>
              </el-form-item>
              <el-form-item label="450.1-500">
                <el-input v-model="list_taobao[10]"></el-input>
              </el-form-item>
            </div>
            <div>
              <el-form-item label="500.1-550">
                <el-input v-model="list_taobao[11]"></el-input>
              </el-form-item>
              <el-form-item label="550.1-600">
                <el-input v-model="list_taobao[12]"></el-input>
              </el-form-item>
              <el-form-item label="600.1-650">
                <el-input v-model="list_taobao[13]"></el-input>
              </el-form-item>
              <el-form-item label="700.1-750">
                <el-input v-model="list_taobao[14]"></el-input>
              </el-form-item>
              <el-form-item label="750.1-800">
                <el-input v-model="list_taobao[15]"></el-input>
              </el-form-item>
              <el-form-item label="800.1-850">
                <el-input v-model="list_taobao[16]"></el-input>
              </el-form-item>
              <el-form-item label="850.1-900">
                <el-input v-model="list_taobao[17]"></el-input>
              </el-form-item>
              <el-form-item label="900.1-950">
                <el-input v-model="list_taobao[18]"></el-input>
              </el-form-item>
              <el-form-item label="950.1-1000">
                <el-input v-model="list_taobao[19]"></el-input>
              </el-form-item>
              <el-form-item label="1000以上">
                <el-input v-model="list_taobao[20]"></el-input>
              </el-form-item>
            </div>
          </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialog_taobao = false">取消</el-button>
        <el-button type="primary" @click="make_price_taobao()">确 定</el-button>
      </span>
      </el-dialog>
<!--      制定拼多多价格-->
      <el-dialog
        title="制定拼多多价格"
        width="50%"
        :visible.sync="dialog_pdd">
        <el-form :model="list_pdd" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <div style="display:flex;">
            <div>
              <el-form-item label="0 - 20">
                <el-input v-model.number="list_pdd[0]" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="20.1 - 50">
                <el-input v-model.number="list_pdd[1]" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="50.1 - 100">
                <el-input v-model.number="list_pdd[2]"></el-input>
              </el-form-item>
              <el-form-item label="100.1 - 150">
                <el-input v-model.number="list_pdd[3]"></el-input>
              </el-form-item>
              <el-form-item label="150.1 - 200">
                <el-input v-model.number="list_pdd[4]"></el-input>
              </el-form-item>
              <el-form-item label="200.1 - 250">
                <el-input v-model.number="list_pdd[5]"></el-input>
              </el-form-item>
              <el-form-item label="250.1 - 300">
                <el-input v-model.number="list_pdd[6]"></el-input>
              </el-form-item>
              <el-form-item label="300.1 - 350">
                <el-input v-model.number="list_pdd[7]"></el-input>
              </el-form-item>
              <el-form-item label="350.1 - 400">
                <el-input v-model.number="list_pdd[8]"></el-input>
              </el-form-item>
              <el-form-item label="400.1-450">
                <el-input v-model.number="list_pdd[9]"></el-input>
              </el-form-item>
              <el-form-item label="450.1-500">
                <el-input v-model.number="list_pdd[10]"></el-input>
              </el-form-item>
            </div>
            <div>
              <el-form-item label="500.1-550">
                <el-input v-model.number="list_pdd[11]"></el-input>
              </el-form-item>
              <el-form-item label="550.1-600">
                <el-input v-model.number="list_pdd[12]"></el-input>
              </el-form-item>
              <el-form-item label="600.1-650">
                <el-input v-model.number="list_pdd[13]"></el-input>
              </el-form-item>
              <el-form-item label="700.1-750">
                <el-input v-model.number="list_pdd[14]"></el-input>
              </el-form-item>
              <el-form-item label="750.1-800">
                <el-input v-model.number="list_pdd[15]"></el-input>
              </el-form-item>
              <el-form-item label="800.1-850">
                <el-input v-model.number="list_pdd[16]"></el-input>
              </el-form-item>
              <el-form-item label="850.1-900">
                <el-input v-model.number="list_pdd[17]"></el-input>
              </el-form-item>
              <el-form-item label="900.1-950">
                <el-input v-model.number="list_pdd[18]"></el-input>
              </el-form-item>
              <el-form-item label="950.1-1000">
                <el-input v-model.number="list_pdd[19]"></el-input>
              </el-form-item>
              <el-form-item label="1000以上">
                <el-input v-model.number="list_pdd[20]"></el-input>
              </el-form-item>
            </div>
          </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialog_pdd = false">取消</el-button>
        <el-button type="primary" @click="make_price_pdd()">确 定</el-button>
      </span>
      </el-dialog>
<!--      添加-->
      <el-dialog
        title="添加"
        width="50%"
        :visible.sync="dislaoging">
        <div style="display:flex;">
            <span></span>
        </div>
      </el-dialog>
    </div>
  </d2-container>
</template>
<script>
import { shop_price_get,shop_price_post,pricec } from "@/api/sys.login";
import axios from "axios";
export default {
  name: "index",
  data() {
    return {
      tableData: [],
      list_pdd:[],
      dialog_pdd:false,
      ruleForm: {
        num:"",
        money:"",
        shop:"",
        deduct:"",
        cost:"",
        task:""
      },
      dislaoging:false,
      row_pdd:{},
      row_taobao:{},
      row_dy:{},
      token:this.$cookies.get('d2admin-1.8.0-token'),
      value1:null,
      options: [],
      value: '',
      list:[],
      list_taobao:[],
      dialog_taobao:false,
      page: 1,
      dialogVisible:false,
      dialog:false,
      total:null,
      babyinfo:null,
      page_size:10,
      cooperation_name:null
    }
  },
  methods: {
    //制定拼多多价格
    look_price_pdd(row){
      this.dialog_pdd = true
      this.row_pdd = row
      this.$axios.get('/api/cooperations/ShopPrice?user='+row.user,{
        headers:{
          'X-token':this.token
        }
      }).then((res)=>{
        this.list = JSON.parse(res.data.data.result.dy_price)
        this.list_taobao = JSON.parse(res.data.data.result.info)
        this.list_pdd = JSON.parse(res.data.data.result.pdd_price)
      })
    },
    //制定淘宝价格
    look_price_taobao(row){
      this.dialog_taobao = true
      this.row_taobao = row
      this.$axios.get('/api/cooperations/ShopPrice?user='+row.user,{
        headers:{
          'X-token':this.token
        }
      }).then((res)=>{
        this.list = JSON.parse(res.data.data.result.dy_price)
        this.list_taobao = JSON.parse(res.data.data.result.info)
        this.list_pdd = JSON.parse(res.data.data.result.pdd_price)
      })
    },
    //制定抖音价格
    look_price(row){
      this.dialog = true
      this.row_dy = row
      console.log(this.row_dy);
      this.$axios.get('/api/cooperations/ShopPrice?user='+row.user,{
        headers:{
          'X-token':this.token
        }
      }).then((res)=>{
        this.list = JSON.parse(res.data.data.result.dy_price)
        this.list_taobao = JSON.parse(res.data.data.result.info)
        this.list_pdd = JSON.parse(res.data.data.result.pdd_price)
      })
    },
    //确认淘宝价格
    make_price_taobao(){
      let params = {
        user:this.row_taobao.user,
        info:JSON.stringify(this.list_taobao),
        money:this.row_taobao.info,
        dy_price:JSON.stringify(this.list),
        pdd_price:JSON.stringify(this.list_pdd)
      }
      shop_price_post(params).then((res)=>{
        if(res.status == 200){
          this.$message({
            type:'success',
            message:res.message
          })
          this.dialog_taobao = false
          this.agenlists()
        }else{
          this.$message({
            type:'error',
            message:res.message
          })
        }
      })
    },
    //确认抖音价格
    make_price(){
      let params = {
        user:this.row_dy.user,
        info:JSON.stringify(this.list_taobao),
        money:this.row_dy.info,
        dy_price:JSON.stringify(this.list),
        pdd_price:JSON.stringify(this.list_pdd)
      }
      shop_price_post(params).then((res)=>{
        if(res.status == 200){
          this.$message({
            type:'success',
            message:res.message
          })
          this.dialog = false
          this.agenlists()
        }else{
          this.$message({
            type:'error',
            message:res.message
          })
        }
      })
    },
    //确认拼多多价格
    make_price_pdd(){
      let params = {
        user:this.row_pdd.user,
        info:JSON.stringify(this.list_taobao),
        money:this.row_pdd.info,
        dy_price:JSON.stringify(this.list),
        pdd_price:JSON.stringify(this.list_pdd)
      }
      shop_price_post(params).then((res)=>{
        if(res.status == 200){
          this.$message({
            type:'success',
            message:res.message
          })
          this.dialog_pdd = false
          this.agenlists()
        }else{
          this.$message({
            type:'error',
            message:res.message
          })
        }
      })
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex%2 == 1) {
        return 'warning-row';
      } else{
        return 'success-row';
      }
      return '';
    },
    handleCurrentChange(val) {
      this.page = val
      this.agenlists()
    },
    agenlists() {
      this.$axios.get('/api/cooperations/Prices?page='+this.page+'&pageSize='+this.page_size,{
        headers:{
          'X-token':this.token
        }
      }).then((res) => {
        if(res.status == 200){
          this.tableData = res.data.data
          console.log(this.tableData,'1111111111111111111111111111');
          this.total = res.data.count
        }else{
          this.$message({
            type:'error',
            message:res.data.message
          })
        }
      });
    }
  },
  created(){
    this.agenlists()
  }
}
</script>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
